/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kylingroup.Desktop.Database;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author kylin
 */
public class DBLocalSQLite implements DBConnection{
    
    private static final String DBURL="jdbc:sqlite:data.db";
    private Connection conn=null;
    
    @Override
    public Connection getConnection(){
        Connection connection=null;
        try{
            connection = DriverManager.getConnection(DBURL);
            java.sql.Statement statement = connection.createStatement();
            statement.setQueryTimeout(30);
        }catch(SQLException e){
            e.getMessage();
        }
        return connection;
    }

    @Override
    public void close(Connection conn) {
        if(conn!=null){
            try{
            	conn.close();
            }catch(SQLException e){
                e.printStackTrace();
            }
	}
    }

    @Override
    public void close(PreparedStatement pstmt) {
        if(pstmt!=null){
            try{
            	pstmt.close();
            }catch(SQLException e){
            	e.printStackTrace();
            }
	}	
    }

    @Override
    public void close(Statement stmt) {
        if(stmt!=null){
            try {
                stmt.close();
            } catch (SQLException ex) {
                Logger.getLogger(DBLocalSQLite.class.getName()).log(Level.SEVERE, null, ex);
            }
	}
    }

    @Override
    public void close(ResultSet rs) {
        if(rs!=null){
            try{
            	rs.close();
            }catch(SQLException e){
            	e.printStackTrace();
            }
	}
    }

    @Override
    public void closeAll(ResultSet rs, Statement stmt, PreparedStatement pstmt, Connection conn) {
        if(rs!=null){
            try{
            	rs.close();
            }catch(SQLException e){
            	e.printStackTrace();
            }
		}if(stmt!=null){
			try{
				stmt.close();
	        }catch(SQLException e){
	        	e.printStackTrace();
	        }
		}if(pstmt!=null){
            try{
            	pstmt.close();
            }catch(SQLException e){
            	e.printStackTrace();
            }
		}if(conn!=null){
            try{
            	conn.close();
            }catch(SQLException e){
            	e.printStackTrace();
            }
	}
    }
    
}
